<template>
	<view>
		<view class="bg display-between-center padding-bottom-border personal" style="padding: 0 30rpx;margin-bottom: 16rpx;height: 80px;" @tap="imgs">
			<view class="text" style="width: 80%;">头像</view>
			<image  :src="user.avatar" mode=""></image>
			<u-icon name="arrow-right" color="#999999" size="28"></u-icon>
		</view>
		<view class="bg display-between-center padding-bottom-border" style="padding: 0 30rpx;">
			<view class="text">昵称</view>
			<input type="text" value="" v-model="user.nickname" :placeholder="user.nickname" class="font-size-28 text-right" placeholder-class="placeholder-class" />
			
		</view>
		<view v-if="user.is_lc==1" class="bg display-between-center padding-bottom-border" style="padding: 0 30rpx;">
			<view class="text">联创区域</view>
			
			<input type="text" v-if="address=='选择/定位'" value="" v-model="address"  @click="show_add=true" class="font-size-28 text-right" placeholder-class="placeholder-class" />
			
			<input type="text" v-else :disabled="true" value="" v-model="address"   class="font-size-28 text-right" placeholder-class="placeholder-class" />
			
		</view>
		<!-- <view class="con_1">
			<view class="display bor_bottom just_space" style="height: 60px;justify-content: space-between;">
				<view class="left">收货地址</view>
				<view class="display " @tap="show=true">
					<view class="p_right_10 c-999" style="font-size: 14px;color: #333;">{{address}}</view>
					<u-icon name="arrow-right" color="#dddddd" size="26" style="padding-top: 5rpx;"></u-icon>
				</view>
			</view>
			<view class="" style="padding: 20px 0;">
				<view class="left">
					详细地址
				</view>
				<u-input v-model="addressInfo.address" type="textarea" height="150" :auto-height="true" />
			</view>
		</view> -->
		<!-- <picker mode="date"  @change="chooseBirthday"> -->
			<!-- <view class="display-between-center" style="">
				<view class="displayLeft">生日</view>
				<view class="display" style="display: flex;">
					<input type="text" v-model="user.birthday" disabled class="text-right mr-10"  placeholder-class="placeholder-class" />
					
				</view>
			</view> -->
			<!-- <view class="bg display-between-center padding-bottom-border" style="padding: 0 30rpx;">
				<view class="text">生日</view>
				<input type="text" value="" v-model="user.birthday" disabled class="font-size-28 text-right" placeholder="请选择生日" placeholder-class="placeholder-class" />
				<u-icon name="arrow-right" color="#999999" size="8"></u-icon>
			</view> -->
		<!-- </picker> -->
		<!-- <view class="bg display-between-center padding-bottom-border" style="padding-right: 30rpx;">
			<view class="text">姓名</view>
			<input type="text" v-model="user.name" maxlength="18" placeholder="请填写" class="font-size-28 text-right" placeholder-class="placeholder-class" />
		</view> -->
		<!-- <view class="bg display-between-center padding-bottom-border" style="padding-right: 30rpx;">
			<view class="text">手机号码</view>
			
			<input type="text" v-model="user.phone" maxlength="18" placeholder="手机号" class="font-size-28 text-right" placeholder-class="placeholder-class" />
		</view> -->
		<!-- <view class="btn" style="margin-top: 100rpx;margin-bottom: 40rpx;" @click="save">
			<button type="default">保存</button>
		</view> -->
		<view class="btn" @tap="save">
			保存
		</view>
		
		
		<!-- 选择地区 -->
		<u-picker mode="region" v-model="show_add" :area-code='["13", "1303", "130304"]' @confirm="select_address"></u-picker>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				idcardnum:'',
				name:'',
				phone:'',
				url:'http://hy.dobest.site/api/',
				user:{
					name:'',
					phone:'',
					nickname:'',
					avatar:'',
					birthday:'',
					province_name:'',
					area_name:'',
					city_name:'',
					is_agent:0,
				},
				address:"选择/定位",
				show_add:false,
				is_agent:0,
				// imgss:'../../static/addCar.png'
				// imageUrl:'https://yueche.sdyilian.top'
			}
		},
		onShow(){
			// this.save()
			// this.user.nickName = uni.getStorageSync('nickName')
			// this.user.imgss = uni.getStorageSync('portrait')
			// console.log(uni.getStorageSync('nickName'),'454545');
		},
		onLoad() {
			this.$myRequest({
				url: 'api/user/index',
				method:'POST',
			}).then(res => {
				if(res.data.code==1){
					// this.$all.setData('user',res.data.data.info)
					this.user=res.data.data.info
					this.is_agent=this.user.is_agent;
					if(this.user.area_name&&this.user.is_lc==1){
						this.address=this.user.province_name+this.user.city_name+this.user.area_name;
					}
				}
			})
		},
		methods: {
			select_address(e){ //选择省市区
				this.user.province_name=e.province.label;
				this.user.city_name=e.city.label
				this.user.area_name=e.area.label
				this.address=e.province.label+e.city.label+e.area.label
			},
			bindPhone(){
				uni.navigateTo({
					url:'bindPhone'
				})
			},
			chooseBirthday(e){
				console.log(e.detail.value);
				this.user.birthday = e.detail.value
			},
			imgs(){
				console.log(uni.getStorageSync('user'));
				uni.chooseImage({
				    success: (chooseImageRes) => {
				        const tempFilePaths = chooseImageRes.tempFilePaths;
				        uni.uploadFile({
				            url:'https://ycxkz.chentu.fun/api/common/upload', //仅为示例，非真实的接口地址
				            filePath: tempFilePaths[0],
				            name: 'file',
							// header:{
							// 	token:
							// },
				            formData: {
				                'file1': 'test',
								// token:uni.getStorageSync('user').token
				            },
				            success: (uploadFileRes) => {
				                console.log(JSON.parse(uploadFileRes.data).data.file);
								this.user.avatar = JSON.parse(uploadFileRes.data).data.url
				            }
				        });
				    }
				});
			},
			save(){
				var post_data={
					token:uni.getStorageSync('user').token,
					username:this.user.nickname,
					// birthday:this.user.birthday,
					avatar:this.user.avatar
				}
				if(this.user.is_lc==1){
					post_data.province_name=this.user.province_name;
					post_data.city_name=this.user.city_name
					post_data.area_name=this.user.area_name
				}
				this.$myRequest({
					url: 'api/user/profile',
					method:'POST',
					data:post_data,
				}).then(res => {
					uni.showToast({
						icon:'none',
						title:res.data.msg
					})
					if(res.data.code==1){
						setTimeout(function() {
							uni.navigateBack({
								data:1
							})
						}, 2000);
						// uni.setStorageSync('nickName',res.data.data.nickname)
						// uni.setStorageSync('portrait',res.data.data.portrait)
						
					}else if(res.data.code==441){
						this.address="选择/定位";
						this.user.province_name='';
						this.user.city_name='';
						this.user.area_name='';
					}
				})
			}
		},
	}
</script>

<style lang="scss">
page{
	background-color: #FAFAFA;
	// width: 93%;
	margin: auto;
	color:#333333;
	.btn{
		margin-top: 40rpx;
		button{
			height: 88rpx;
			background: #4567F2;
			border-radius: 4px;
			font-size: 30rpx;
			color: #FFFFFF;
		}
	}
	.text{
		font-size: 28rpx;
		color: #333;
	}
	.idCardUp{
		margin: 40rpx 0 24rpx 0;
		font-size: 28rpx;
		color: #333333;
	}
	.idCardBox{
		display: flex;
		justify-content: space-between;
		.idCardText{
			font-size: 20rpx;
			color: #999999;
			text-align: center;
		}
	}
	.personal{
		image{
			width: 80rpx;
			height: 80rpx;
			border-radius: 50%;
		}
	}
	input{
		width: 80%;
	}
	.btn{
		height: 50px;
		line-height: 50px;
		text-align: center;
		background: #FF9101;
		font-size: 16px;
		font-family: PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		opacity: 1;
		border-radius: 32px;
		margin-bottom: 10px;
	}
}
</style>
